﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Aierp.Utility.Data
{
    public class PageInfo
    {
        public int Total { get; set; }
        public int Limit { get; set; }
        public int Offset { get; set; }

        public PageInfo(int total, int limit, int offset)
        {
            var result = GetPageSize(total, limit, offset);

            this.Limit = result.Item1;
            this.Offset = result.Item2;
            this.Total = total;
        }

        public static Tuple<int, int> GetPageSize(int total, int limit, int offset)
        {
            if (limit > 1000) limit = 100;
            if (limit > total)
            {
                limit = total;
                offset = 0;
            }
            return new Tuple<int, int>(limit, offset);
        }
    }

    public class PageRequestParam
    {
        public string Order { get; set; }
        public int Limit { get; set; }
        public int Offset { get; set; }

        public string SearchModel { get; set; }
    }

}
